<?php
    include ($_SERVER['DOCUMENT_ROOT']."/CTAN/config/ConnectDB.php");
    class NgheSi extends ConnectDB{
        private $id;
        private $tenThat;
        private $ngheDanh;
        private $ngaySinh;
        private $tieuSu;
        private $conHoatDong;
        private $like;
        
        public function getId() {
            return $this->id;
        }

        public function setId($id) {
            $this->id = $id;
        }

        public function getTenThat() {
            return $this->tenThat;
        }

        public function setTenThat($tenThat) {
            $this->tenThat = $tenThat;
        }

        public function getNgheDanh() {
            return $this->ngheDanh;
        }

        public function setNgheDanh($ngheDanh) {
            $this->ngheDanh = $ngheDanh;
        }

        public function getNgaySinh() {
            return $this->ngaySinh;
        }

        public function setNgaySinh($ngaySinh) {
            $this->ngaySinh = $ngaySinh;
        }

        public function getTieuSu() {
            return $this->tieuSu;
        }

        public function setTieuSu($tieuSu) {
            $this->tieuSu = $tieuSu;
        }

        public function getConHoatDong() {
            return $this->conHoatDong;
        }

        public function setConHoatDong($conHoatDong) {
            $this->conHoatDong = $conHoatDong;
        }

        public function getAnhDaiDien() {
            return $this->anhDaiDien;
        }

        public function setAnhDaiDien($anhDaiDien) {
            $this->anhDaiDien = $anhDaiDien;
        }

        public function getLike() {
            return $this->like;
        }

        public function setLike($like) {
            $this->like = $like;
        }
        
        /*
         * Thêm vào CSLD một dòng dữ liệu về ca sĩ
         * Trả về số dòng thêm thành công
         */
        public function themNgheSi(){
            $insert_query = "INSERT INTO nghe_si(ten_that, nghe_danh, ngay_sinh, tieu_su, con_hoat_dong, luot_like) VALUES (
                            '".$this->tenThat."',
                            '".$this->ngheDanh."',
                            '".$this->ngaySinh."',
                            '".$this->tieuSu."',
                            '".$this->conHoatDong."',
                            '".$this->like."')";
            $this->setQuery($insert_query);
            $this->executeQuery();
            if ($this->getResult()){
                $getIdCommand = "SELECT MAX(ma_nghe_si) as id FROM nghe_si";
                $this->setQuery($getIdCommand);
                $res = $this->executeQuery();
                while ($row = mysql_fetch_array($res)) {
                    $this->id=$row["id"];
                }
                return $this->id;
            }
            else return $this->getResult();
        }
        
        /*
         * Cập nhật thông tin ca sĩ vào CSLD  
         */
        public function capNhatNgheSi(){
            $update_query = "UPDATE nghe_si SET ten_that='".$this->tenThat."',
			nghe_danh='".$this->ngheDanh."',
			ngay_sinh='".$this->ngaySinh."',
			tieu_su='".$this->tieuSu."',
			con_hoat_dong='".$this->conHoatDong."',
			luot_like='".$this->like."' WHERE ma_nghe_si='".$this->id."'";
            $this->setQuery($update_query);
            return $this->executeQuery();
        }
        
        /*
         * Xóa một thông tin ca sĩ
         */
        public function xoaNgheSi(){
            $delete_query = "DELETE FROM nghe_si WHERE ma_nghe_si='".$this->id."'";
            $this->setQuery($delete_query);
            return $this->executeQuery();
        }
        
        public function danhSachNgheSi($isLogedIn){
            if ($isLogedIn) $query = "SELECT SQL_CALC_FOUND_ROWS ma_nghe_si, ten_that, nghe_danh, ngay_sinh, tieu_su, con_hoat_dong, luot_like FROM nghe_si";
            else $query = "SELECT SQL_CALC_FOUND_ROWS ma_nghe_si, ten_that, nghe_danh, ngay_sinh, tieu_su, con_hoat_dong, luot_like FROM nghe_si WHERE con_hoat_dong='1'";
            //$query = $query." LIMIT $start, $pagesize";// order by nghe_danh asc";
            $this->setQuery($query);
            $this->executeQuery();
            return $this->getResult();
        }
    }
?>
